/*Random number generator, real version 2 (QUICK C: Angel Diaz)*/
#include <stdio.h>
#include <float.h>
#include <math.h>
#define a (double) 16807.0
#define m (double) 2147483647.0
#define q (double) 127773.0
#define r (float) 2836.0
float random, randomvar();
double hi, test, lo, seed;

int i=1;
main()
{
  seed=1;
  printf("Initial seed=%10.2f\n", seed);
  printf("______________________________________________\n");
  while(i<10001)
    {	randomvar();
      if(i<11) printf("%5d seed=%10.0f num=%f\n", i, seed, random);
      i++;
    }
  printf("%3d seed=%10.0f num=%f\n", i, seed, random);
}
float randomvar(void)
{      
  hi=floor(seed/q);
  lo=seed-q*hi;
  test=a*lo-r*hi;
  if (test>0.0)
    seed=test;
  else
    seed=test+m;
  random=seed/m;
  return random;
 }

